package com.yanqu.road.web.controller.usercenter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yanqu.road.entity.web.HttpJsonWebParam;
import com.yanqu.road.server.manger.H5AppletUrlMgr;
import com.yanqu.road.utils.string.StringUtils;
import com.yanqu.road.web.controller.BaseJsonHttpServlet;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@WebServlet(urlPatterns = "/h5Veision")
public class H5VersionUrl extends BaseJsonHttpServlet {
    private static Logger logger = LogManager.getLogger(H5ServerList.class.getName());

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        logger.info("request H5VersionUrl");
        String sUserId = request.getParameter("sUserId");
        String nPlatform = request.getParameter("nPlatform");
        int platform = 0;
        try {
            if (!StringUtils.isNullOrEmpty(nPlatform)) {
                platform = Integer.parseInt(nPlatform);
            }
        } catch (Exception e) {
            logger.error("nPlatform error: {}", nPlatform, e);
        }
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("version", H5AppletUrlMgr.getH5Url(sUserId, platform));
        String result = JSON.toJSONString(dataMap);
        sendMessage(response, result);
    }
}
